<extend name="Public/base" />
<block name="content">
    <form action="?" method="get">
    <fieldset>
        <legend>字典查询</legend>
            <volist name="search" id="v">
            <input type="checkbox" name="field" value="<{$v.field}>"><{$v.field}>
            </volist>
            <input type="submit" class="button tiny edit" value="筛选">
        </fieldset>
    </form>

    <table id="dictsTbl">
    <thead>
    <tr>
        <th><input onclick="selectAll(this)" type="checkbox"></th>
        <th>编号</th>
        <th>字段名</th>
        <th>字段值</th>
        <th>字段描述</th>
        <th>是否作废</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
        <volist name="dict" id="v">
            <tr id="row_<{$v.dict_id}>">
                <td><input class="slct" type="checkbox" value="<{$v.dict_id}>"></td>
                <td><{$v.dict_id}></td>
                <td><input  name="field" type="text"  class="a" disabled value="<{$v.field}>"></td>
                <td><input  name="val" type="text" class="a" disabled value="<{$v.val}>"></td>
                <td><input name="desc" type="text" class="a" disabled value="<{$v.desc}>"></td>
                <td>
                    <div class="switch tiny">
                        <input onclick="lock(this)" value="<{$nav.dict_id}>" id="lock_<{$v.dict_id}>" type="checkbox" <{$nav['lock']?'checked':''}> >
                        <label for="lock_<{$v.dict_id}>"></label>
                    </div>
                </td>
                <td>
                    <button onclick="edit('row_<{$v.dict_id}>')" class="button tiny edit">编辑</button>
                    <button onclick="save('<{$v.dict_id}>')" style="display:none;" class="button tiny save">保存</button>
                </td>
            </tr>
        </volist>

    </tbody>
</table>
    <div>
        <span><{$page}></span>
    </div>
    <a class="button tiny" href="<{:U('addDict')}>">添加</a>
    <button onclick="unSelect()" class="button tiny">反选</button>
    <button onclick="delLot()" class="button tiny">删除(批量)</button>

    <script>
        //是否作废
        function lock(obj) {
            var id = $(obj).val();
            var lockval = $(obj).prop('checked')?1:0;
            $.post('<{:U("doEditDict")}>',{menu_id:id,lock:lockval});
        }
        //编辑
        function edit(rowid) {
            $('#'+rowid+' .a').prop('disabled',false);
            $('#'+rowid+' .edit').hide();
            $('#'+rowid+' .save').show();
           // console.log('#'+rowid);exit;
        }
        //保存
        function save(id) {
            $('#row_'+id+' .a').prop('disabled',true);
            $('#row_'+id+' .edit').show();
            $('#row_'+id+' .save').hide();

            var data = {
                dict_id:id,
                field:$('#row_'+id+' [name=field]').val(),
                val:$('#row_'+id+' [name=val]').val(),
                desc:$('#row_'+id+' [name=desc]').val(),
            }

            $.post('<{:U("doEditDict")}>',data,function (data) {
                if(data.error!==0){
                    alert(data.msg);
                }
            });
        }
        //全选
        function selectAll(obj) {
            $('#dictsTbl tbody .slct').prop('checked',$(obj).prop('checked'));
        }
        //反选
        function unSelect() {
            $('#dictsTbl tbody .slct').map(function(){
                $(this).prop('checked',!$(this).prop('checked'));
            });
        }
        //批量删除
        function delLot() {
            if(!confirm('确认批量删除吗')){
                return;
            }
            var ids = $('#dictsTbl tbody .slct:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            $.post('<{:U("doDelDict")}>',{ids:ids},function (data) {
                alert(data.msg);
            });
        }
    </script>
</block>